package ore.example.pokemoninfo.utils;

import ore.example.pokemoninfo.GUI.PhotoConfirmGUI;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.ClickType;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
import xyz.xenondevs.invui.item.ItemProvider;
import xyz.xenondevs.invui.item.impl.AbstractItem;
import xyz.xenondevs.invui.item.ItemWrapper;
import ore.example.pokemoninfo.utils.ConvertPokemon;

public class PokemonSlotItem extends xyz.xenondevs.invui.item.impl.AbstractItem {

    private final ItemStack displayStack;
    private final int partyIndex;

    public PokemonSlotItem(@NotNull ItemStack displayStack, int partyIndex) {
        this.displayStack = displayStack;
        this.partyIndex = partyIndex;
    }

    @Override
    public ItemProvider getItemProvider() {
        // 包装现有 ItemStack
        return new ItemWrapper(displayStack);
    }

    @Override
    public ItemProvider getItemProvider(Player viewer) {
        return super.getItemProvider(viewer);
    }


    @Override
    public void handleClick(@NotNull ClickType clickType, @NotNull Player player, @NotNull InventoryClickEvent event) {
        event.setCancelled(true);

        if (clickType.isLeftClick()) {
            player.closeInventory();
            PhotoConfirmGUI.open(player, partyIndex);
        } else if (clickType.isRightClick()) {
            player.closeInventory();
            ShowPokemonInfoChat.broadcastPokemon(player, displayStack);
        }
    }

}
